from pywinauto import Application, Desktop
import psutil
import pyautogui as pg
import time

process_ids = []
for proc in psutil.process_iter(["pid", "name"]):
    if proc.info["name"] == "WeMeetApp.exe":
        process_ids.append(proc.info["pid"])
        proc.terminate()
meeting_id = "123456789"
user_name = "user"
pg.PAUSE = 1
app = Application().start(r"D:\tencentmeeting\WeMeet\WeMeetApp.exe")
for i in range(10):
    try:
        dlg = Desktop(backend="uia").windows(title="腾讯会议")[0]
        break
    except Exception as e:
        time.sleep(1)
dlg.set_focus()
time.sleep(1)
join_meet = pg.locateCenterOnScreen("join_meet.png", confidence=0.8)
pg.click(join_meet)
# app["加入会议"].print_control_identifiers()
for i in range(10):
    try:
        dlg = Desktop(backend="uia").windows(title="加入会议")[0]
        break
    except Exception as e:
        print(e)
        time.sleep(1)
# pyperclip.copy(meeting_id)
# pg.hotkey("ctrl", "v")
input_meet_num = pg.locateCenterOnScreen("input_meet_num.png", confidence=0.8)
pg.click(input_meet_num)
pg.write(meeting_id)
pg.press("tab")
pg.press("tab")
pg.write(user_name)
join_meet_1 = pg.locateCenterOnScreen("join_meet_1.png", confidence=0.8)
pg.click(join_meet_1)
